/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include <向量.h>
#include "core/结构数据.h"
#include "core/属性.h"
#include "数学/数学.h"

void f_math_视锥平面计算(const Mat44f& mat, vec4 planes[6]) {
	const float32* mat_ptr = (float32*)&mat;
	for (uint32 i = 0; i < 4; ++i) {
	    //右
		((float32*)&planes[0])[i] = mat_ptr[i * 4 + 3] - mat_ptr[i * 4];

		//左
		((float32*)&planes[1])[i] = mat_ptr[i * 4 + 3] + mat_ptr[i * 4];

		//底
		((float32*)&planes[2])[i] = mat_ptr[i * 4 + 3] + mat_ptr[i * 4 + 1];

		//顶
		((float32*)&planes[3])[i] = mat_ptr[i * 4 + 3] - mat_ptr[i * 4 + 1];

		//远
		((float32*)&planes[4])[i] = mat_ptr[i * 4 + 3] - mat_ptr[i * 4 + 2];

		//近
		((float32*)&planes[5])[i] = mat_ptr[i * 4 + 3] + mat_ptr[i * 4 + 2];

	}

	for (uint32 i = 0; i < 6; ++i) {
		vec_normalize(&planes[i]);
	}
}

